﻿using GN.Pay.TradeChannel.WeiXin.Response;
using GN.Pay.Utils.Net.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace GN.Pay.TradeChannel.WeiXin.Request
{
    [Serializable]
    class QueryRequest : AServiceRequest
    {
        private ITradeChannel channel;
        private WeiXinConfigure config;

        public QueryRequest(ITradeChannel channel,
             WeiXinConfigure config,
             string tradeNo,
             string outTradeNo)
        {
            this.channel = channel;
            this.config = config;
            transaction_id = tradeNo;
            out_trade_no = outTradeNo;
            Appid = config.ConfigureInfo.AppId;
            Mch_id = config.ConfigureInfo.AccountId;
        }

        /// <summary>
        /// 微信分配的公众账号ID（企业号corpid即为此appId） 
        /// </summary>
        public string Appid { get; set; }

        /// <summary>
        /// 微信支付分配的商户号
        /// </summary>
        public string Mch_id { get; set; }

        /// <summary>
        /// 业务流水号
        /// </summary>
        public string transaction_id { get; private set; }

        /// <summary>
        /// 商户订单号
        /// </summary>
        public string out_trade_no { get; private set; }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override bool IsAddSignType()
        {
            return false;
        }

        /// <summary>
        /// 生成
        /// </summary>
        /// <returns></returns>
        public QueryResponse Build()
        {
            string requestXml = BuildSignXmlParam(channel, config, "sign", "sign_type");
            string url = "https://api.mch.weixin.qq.com/pay/orderquery";
            string responseString = HttpUtils.PostString(url, requestXml, config.Encoding);
            var res = new QueryResponse(responseString, channel);
            return res;
        }
    }
}
